// import proFetch from "../../../../../public/functions/project-fetch";
import {hrAjax as ajax} from 'src/hrpub/common/utils/utils';
import updateButtonStatus from "./updateButtonStatus";
import handleAllpks from "./handleAllpks";

export default function getMainTableData(conditions) {

    const {orgVal, agreementType,pageInfo} = this.state.orgVal ? this.state : this.props;
    return ajax({
        url: '/nccloud/hrcm/agreement/ReleaseQueryAction.do',
        body: {
            pk_org: orgVal && orgVal.refpk ? orgVal.refpk : null,
            agreementType: agreementType,
            nodecode:'60110507',
            pageInfo: pageInfo,
            ...conditions
        },
    }).then((res) => {
        let tableid = agreementType;
        if (res.success) {
            let dataList;
            if (res.data) {
                if(res.data.postcont){
                    dataList = res.data.postcont;
                }else if(res.data.secrerycont){
                    dataList = res.data.secrerycont;
                }else if(res.data.traincont){
                    dataList = res.data.traincont;
                }else{
                    tableid = agreementType + 'List';
                    dataList = res.data[tableid];
                }
            }
            if(!dataList){
                if(agreementType !== 'postcont' &&  agreementType !== 'secrerycont' && agreementType !== 'traincont'){
                    tableid = agreementType + 'List';
                }
                dataList = {
                    allpks: [],
                    areacode: agreementType,
                    rows: [],
                };
            }else {
                let pks = res.data[tableid].allpks;
                handleAllpks.set(pks);
            }
            this.props.editTable.setTableData(tableid, dataList);
            updateButtonStatus.call(this, orgVal,tableid,false,true);
            let pageInfoData = dataList.pageInfo || pageInfo;
                pageInfoData.pageIndex = pageInfoData.pageIndex * 1;
            this.setState({
                pageInfo: pageInfoData,
                pk_org: orgVal && orgVal.refpk ? orgVal.refpk : null,
                isVisiblePagination: !!dataList && dataList.rows.length ? true : false
            },()=>{
                let { isVisiblePagination, pageInfo } = this.state;
                this.props.setPageShow && this.props.setPageShow(isVisiblePagination, pageInfo);
            });
        }
    });

    function setBoolean( rows) {
        for (let row in rows){
            let data = rows[row].values;
            data.isrefer.display=data.isrefer.value ? '是' : '否'
            data.ifprop.display=data.ifprop.value ? '是' : '否'
        }
    }
}
